//index.js
//获取应用实例
const util=require("../../utils/util.js");
const app = getApp()
const baseImgUrl=util.baseImgUrl;
var i=0;


Page({
  data: {
    indicatorDots: false,//是否显示轮播图的面板指示点
    indicatorDots2:false,

    autoplay: true,//轮播图是否自动播放

    interval: 5000,
    duration: 1000,
    duration2:1000,

    showGrey:true,
    scanPic:baseImgUrl+"scan_home.png",
    s_imgUrls: [baseImgUrl + "lunbo_ceshi.png", baseImgUrl + "lunbo_ceshi.png", baseImgUrl + "lunbo_ceshi.png"],//轮播图路径
    searchPic:baseImgUrl+"search_home.png",
    wb_bgImg: baseImgUrl +"wb_bgImg.png",
    navlist: [{
      id:0,
      picurl:"/pages/images/nav_ceshi1.png",
      name:"小学",
    }, {
        id: 1,
        picurl: "/pages/images/nav_ceshi1.png",
        name: "初中",
      }, {
        id: 2,
        picurl: "/pages/images/nav_ceshi1.png",
        name: "高中",
      }, {
        id: 3,
        picurl: "/pages/images/nav_ceshi1.png",
        name: "大学",
      }],
      morePic: baseImgUrl + "more.png",
    newestlist:[{
      id:0,
      picurl:baseImgUrl+"book_ceshi1.png",
      bookname:"小凤仙故事-小知识大世界小知识大世界小凤仙故事-小知识大世界小知识大世界",
      author:"银河老师银河老师银河老师",
      scan:"123600",
      hasread:0
    }, {
        id: 1,
        picurl: baseImgUrl + "book_ceshi1.png",
        bookname: "小凤仙故事-小知识大世界",
        author: "银河老师",
        scan: "1236",
        hasread: 0
      }, {
        id:2,
        picurl: baseImgUrl + "book_ceshi1.png",
        bookname: "小凤仙故事-小知识大世界",
        author: "银河老师",
        scan: "12360",
        hasread: 0
      }],
    newestlist2: [{
      id: 5,
      picurl: baseImgUrl + "book_ceshi1.png",
      bookname: "添加的数据1",
      author: "银河老师银河老师银河老师",
      scan: "1236",
      hasread: 0
    }, {
      id: 6,
      picurl: baseImgUrl + "book_ceshi1.png",
        bookname: "添加的数据2",
      author: "银河老师",
      scan: "1236",
      hasread: 0
    }, {
      id: 7,
      picurl: baseImgUrl + "book_ceshi1.png",
        bookname: "添加的数据3",
      author: "银河老师",
      scan: "1236",
      hasread: 0
    }],
    wbText: "分享课堂为学习资源共享平台，旨在让每个孩子拥有更多的学习资源，感谢资源的整理者提供者。获得资源需支付服务费用，望请谅解。",
      
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')

  },
  //跳转到了解优当课堂
  know:function(){

  },
  //跳转至搜索页面
  gosearch:function(){

  },
  //进入学堂
  goschool:function(e){
    console.log(e);
    var index=e.currentTarget.dataset.index;
    if(index==3){
      wx.navigateTo({
        url: '/pages/tisheng/tisheng',
      })
    }else{
      wx.navigateTo({
        url: '/pages/school/school',
      })
    }
  },

  //事件处理函数
  goDetail: function(e) {
    console.log(e);
    var that=this;
    var newid=e.currentTarget.dataset.id;

    wx.navigateTo({
      url: '/pages/audioDetail/audioDetail?newid=' + newid,
    })
  },

  goDetail2:function(e){
    var that = this;
    var newid = e.currentTarget.dataset.id;
    var index_now=e.currentTarget.dataset.index;
    that.data.newestlist[index_now].hasread=1;
    that.setData({
      newestlist: that.data.newestlist
    })
   
    wx.navigateTo({
      url: '/pages/audioDetail/audioDetail?newid=' + newid,
    })

  },
  onLoad: function () {
    
    wx.getSystemInfo({
      success: function(res) {
        console.log("系统"+res.windowHeight);
      },
    })
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }

    

  },

  ///我再想想
  wait: function () {
    var that = this;
    that.setData({
      showGrey:false
    })
  },
  //开通会员
  member: function () {
    var that = this;
    that.setData({
      showGrey: false
    })
    // wx.navigateTo({
    //   url: '',
    // })
  },
    
 
  //到底
  onReachBottom:function(){
      
      console.log("*********到达底部*************")
      util.loading();
      //请求接口
      var that=this;
      var newestlist=that.data.newestlist;
      var arr = that.data.newestlist2;
     
    if(i<4){
      newestlist = newestlist.concat(arr);
      that.setData({
        newestlist: newestlist
      })
      i++;
     console.log("*****************"+i+"*****************");
    }
    if(i==4){
      wx.showToast({
        icon:"none",
        title: '没有更多数据了',
      })
    }
    
    
     
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})

